#!/bin/bash

JAR_NAME=$(basename $1)
APP_NAME=`echo ${JAR_NAME} | cut -d "." -f1`
PEM_PATH=/f/dev1.pem

echo APP_NAME: ${APP_NAME}

echo "------Upload Application("${APP_NAME}")------"
scp -vC -i -q "${PEM_PATH}" $1 root@dev1.yungu-link.com:~/

echo "------Deploy Application("${APP_NAME}")------"
ssh-add -k "${PEM_PATH}"
ssh root@dev1.yungu-link.com \
"mkdir -p /home/sky/apps-jar/"${APP_NAME}" ;
cd /home/sky/apps-jar/"${APP_NAME}" ;
mv "$JAR_NAME" "$JAR_NAME"-backup ;
mv /root/"$JAR_NAME" ./ ;
cd ../ ;
sh app-start.sh "${APP_NAME}"/"${JAR_NAME}" >/dev/null 2>&1 ;
tailf -n 200 "${APP_NAME}"/start.logger"